package com.zhuxiang.server;

import com.zhuxiang.model.Student;
import com.zhuxiang.model.UserMessage;

import java.io.IOException;

/**
 * 编程实现服务器的主功能
 */
public class ServerView {

    private Server server;
    private ServerDao sd;

    public ServerView(Server server,ServerDao sd){
        this.server = server;
        this.sd = sd;
    }

    public void serverReceive() throws IOException, ClassNotFoundException {
        UserMessage temp = (UserMessage) server.getOis().readObject();
        if (temp.getType().equals("managerCheck")){
            if (sd.serverManagerCheck(temp.getUser())){
                temp.setType("success");
            }else {
                temp.setType("fail");
            }
        }else {
            if (sd.serverUserCheck(temp.getUser()) == 1){
                temp.setType("success");
            }else if (sd.serverUserCheck(temp.getUser()) == -1){
                temp.setType("fail");
            }else {
                temp.setType("add");
            }
        }
        //将校验结果发送给客户端
        server.getOos().writeObject(temp);
        System.out.println("服务器发送校验结果成功");
    }
}
